<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/6/7
 * Time: 1:51
 */

namespace app\api\controller\v7;

use app\api\controller\v2\Auth;
use app\common\lib\exception\ApiException;
use app\common\model\FortuneCache;
use app\common\model\Recode;


/**
 * @title 每日运势相关接口
 * @desc
 * @url
 * @version 1.3.0
 * Class Fortune
 * @package app\api\controller\v2
 */
class Fortune extends Auth
{
    protected $nodel;

    protected $active_switch;

    public function _initialize()
    {
        parent::_initialize();

        $this->nodel = config('code.nodel');
        $this->active_switch = false;
//        $this->active_switch = checktime();
    }

    /**
     * @title 每日运势详情
     * @method GET
     * @desc
     * @return \think\response\Json
     * @throws \app\common\lib\exception\ApiException
     */

    public function index()
    {
        if (!request()->isGet())
        {
            return show(config('code.error'), '未知操作', [], 403);
        }
        $rid = input('get.rid/d', 0);
        // 当前时间
        $time = strtotime(date('Y-m-d', input('get.time/d')));
        $uid = (int)$this->user['id'];

        if (!$rid) throw new ApiException('档案信息获取失败');

        $recode = (new Recode())->getRecode(['id' => $rid]);
        if (!$recode || $recode['uid'] != $this->user['id'])
        {
            return show(config('code.error'), '档案不存在');
        }

        //获取日运详情数据
        $data = (new FortuneCache())->getIndexInfo($uid, $time, $rid, $this->active_switch);

        return show(200, '加载成功', $data);
    }

}
